<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="main">
        <div class="box"><p>段落1</p></div>
        <div class="box"><p>段落2</p></div>
        <div class="box"><p>段落3</p></div>
        <input type="text" name="sex">
    </div>
</body>
<script>
    // 根据id获取元素
    var doc=document.getElementById('main')
    console.log(doc)
    // 根据标签名获取元素
    var p=document.getElementsByTagName('p')
    console.log(p)
    var div=document.getElementsByTagName('div')
    console.log(div)
    // 根据class名获取元素
    var box=document.getElementsByClassName('box')
    console.log(box)
    var sex=document.getElementsByName('sex')
</script>
</html>